<?php
class Admin_Model_User extends Zend_Db_Table_Abstract
{
	public  function  add($fullname,$username,$pass,$id_group,$address,$phone,$email,$active,$folder)
	{
		$db = Zend_Registry::get('connectDB');
		$data = array('fullname'=>$fullname,'username'=>$username,'password'=>$pass,'id_group'=>$id_group,'address'=>$address,'phone'=>$phone,'email'=>$email,'active'=>$active,'folder_user'=>$folder);
		$insert = $db->insert('users',$data);
		return $insert;
	}
	public function getallgroup()
	{
		$db = Zend_Registry::get('connectDB');
		$data = $db->fetchAll($db->select()->from('groups'));
		return $data;
	}
	public function getidgroup($group)
	{
		$db = Zend_Registry::get('connectDB');
		$data = $db->fetchRow($db->select()->from('groups','id_group')->where('name_group = ?',$group));
		return $data;
	}
	public function getuserAll()
	{
		$db = Zend_Registry::get('connectDB');
		$data = $db->fetchAll($db->select()->from('users')->joinInner('groups','users.id_group=groups.id_group'));
		return $data;
	}
	public function search($content)
	{
		$db = Zend_Registry::get('connectDB');
		$where = $db->quoteInto('fullname LIKE ? OR username LIKE ? OR registrydate LIKE ? OR name_group','%'.$content.'%');
		$data = $db->fetchAll($db->select()->from('users')->joinInner('groups','users.id_group=groups.id_group')->where($where));
		return $data;
	}
	public function delete($id)
	{
		$db = Zend_Registry::get('connectDB');
		$where = $db->quoteInto('id_user = ?',$id);
		$delete = $db->delete('users',$where);
		return $delete;
	}
	public function getId($id)
	{
		$db = Zend_Registry::get('connectDB');
		$data = $db->fetchRow($db->select()->from('users')->where('id_user = ?',$id));
		return $data;
	}
	public function edit($id,$fullname,$username,$pass,$id_group,$address,$phone,$email,$active)
	{
		$db = Zend_Registry::get('connectDB');
		$data = array('fullname'=>$fullname,'username'=>$username,'password'=>$pass,'id_group'=>$id_group,'address'=>$address,'phone'=>$phone,'email'=>$email,'active'=>$active);
		$where = $db->quoteInto('id_user =?',$id);
		$update = $db->update('users',$data,$where);
		return $update;
	}
	public function active($id,$active)
	{
		$db = Zend_Registry::get('connectDB');
		$data = array('active'=>$active);
		$where = $db->quoteInto('id_user =?',$id);
		$update = $db->update('users',$data,$where);
		return $update;
	}
	public function disable($id,$disable)
	{
		$db = Zend_Registry::get('connectDB');
		$data = array('active'=>$disable);
		$where = $db->quoteInto('id_user =?',$id);
		$update = $db->update('users',$data,$where);
		return $update;
	}
	public function status($id,$status)
	{
		$db = Zend_Registry::get('connectDB');
		$data = array('status'=>$status);
		$where = $db->quoteInto('id_user =?',$id);
		$update = $db->update('users',$data,$where);
		return $update;
	}
}